<template>
	<div class="app-container" v-loading="loading" element-loading-text="加载中">
		<el-row :style="{ flexGrow: 1, overflowY: 'auto' }">
			<!-- 中间可滑动的区域 -->
			<OrderUnity :showall=true :isedit=true ref="orderUnity">
			</OrderUnity>
		</el-row>
		<el-row>
			<el-col :span="24" style="position: fixed; bottom: 0; width: 100%; z-index:100;">
				<!-- 底部固定的区域 -->
				<el-form style="background-color: white;">
					<el-button type="danger" @click="handlePost()" style="text-align: center;">完成工单</el-button>
				</el-form>
			</el-col>
		</el-row>
	</div>
</template>

<script>
import { tr } from '@dcloudio/vue-cli-plugin-uni/packages/postcss/tags'
import Api from '../../api/api'
import OrderUnity from '../../components/orderunity.vue'
export default {
	components: {
		OrderUnity,
	},
	data() {
		return {
			loading:false
		}
	},
	methods: {
		onLoad(e) {
			console.log(e._id)
			Api.getWorkOrders({ search: { _id: e._id } }).then(response => {
				console.log(response.data)
				if (response.status == 200) {
					if (response.data.data[0].member_list)
						this.member_list = response.data.data[0].member_list
					this.$refs.orderUnity.setFormData(response.data.data[0]);
				}
			})
		},
		handlePost() {
			this.loading = true
			const formData = this.$refs.orderUnity.getFormData();
			let mentioned_mobile_list = []
			mentioned_mobile_list.push(formData.repairman._id)
			// 使用 formData 对象进行处理
			let content = "工单已完成" +
				"\n客户:" + formData.customer.name +
				"\n维修人员:"+formData.repairman.name +
				"\n指派人员:"+formData.assignee.name +
				"\n连接:" + Api.baseWebUrl + "#/pages/tabbar/orders/orders?order_id="+formData._id
			let message = {
				"msgtype": "text",
				"text": {
					"content": content,
					"mentioned_mobile_list": mentioned_mobile_list
				}
			}

			console.log(message)
			Api.sendGroupMessages(message).then(response => {
				console.log(response.data)
				if (response.status == 200) {
					formData.assignee = formData.assignee._id
					formData.customer = formData.customer._id
					formData.repairman = formData.repairman._id
					formData.status = 3
					console.log("formData", formData)
					Api.updaWorkOrders({ id: formData._id, date: formData }).then(response => {
						console.log(response.data)
						if (response.status == 200) {
							uni.reLaunch({ url: '/pages/tabbar/orders/orders?status=2' })
						}
						this.$message.success(response.data.message);
						this.loading = false
					})
				}
			})
		}
	}
}
</script>

<style>
.app-container {
	display: flex;
	flex-direction: column;
	height: 100%;
}

.el-form {
	display: flex;
	justify-content: center;
}

.el-button {
	margin: auto;
}
</style>
